package com.biodiv.miracle.ioc.factory;

import com.biodiv.miracle.aop.aspect.AspectObject;
import com.biodiv.miracle.ioc.core.BeanFactory;
import com.biodiv.miracle.aop.proxy.ProxyRegistration;

import java.lang.annotation.Annotation;
import java.util.List;
import java.util.logging.Logger;

/**
 * @Author: tianquan
 * @CreateTime: 2024-09-28  22:12
 * @Description: 默认bean工厂
 */
public class DefaultBeanFactory extends AbstractBeanFactory implements BeanFactory {

    private final Logger logger = Logger.getLogger(DefaultBeanFactory.class.getName());
    private final ProxyRegistration proxyRegistration;

    public DefaultBeanFactory() {
        proxyRegistration = new ProxyRegistration();
    }

    @Override
    public Object getBean(String name) {
        return getSingletonBean(name);
    }

    @Override
    public <T> T getBean(Class<T> aClass) {
        return getSingletonBean(aClass);
    }

    @Override
    public boolean containsBean(String name) {
        return containsKey(name);
    }

    @Override
    public boolean removeBeanDefinition(String name) {
        return false;
    }

    @Override
    public boolean containsBean(Class<?> aClass) {
        return containsValue(aClass);
    }

    @Override
    public <T> List<T> getBeans(Class<T> aClass) {
        return getBeansOfType(aClass);
    }

    public void putAopAnnotationName(Class<? extends Annotation> annotation, AspectObject aspectObject) {
        proxyRegistration.putAopAnnotationName(annotation, aspectObject);
    }

    public void putAopMethodsName(String method, AspectObject aspectObject) {
        proxyRegistration.putAopMethodsName(method, aspectObject);
    }

    public void putAopClass(Class<?> className, AspectObject aspectObject) {
        proxyRegistration.putAopClass(className, aspectObject);
    }

    public ProxyRegistration getProxyBeanFactory() {
        return proxyRegistration;
    }
}
